package com.example.day08;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class RandomAccessFileTest {
    public static void main(String[] args) throws IOException {
        RandomAccessFile randomAccessFile = new RandomAccessFile("raf.txt", "rw");
//        randomAccessFile.writeInt(123);
        // seek 寻找 I seek U ICQ OICQ QQ
//        randomAccessFile.seek(0); // pos = position
//        System.out.println(randomAccessFile.readInt()); // EOF = End Of File

        for (int i = 0; i < 10; i++) {
            randomAccessFile.writeDouble(i * i);
        }

        // 16.0 -> 0.0 ?
        randomAccessFile.seek(8 * 4);
        randomAccessFile.writeDouble(0.0);

        randomAccessFile.seek(0);

        for (int i = 0; i < 10; i++) {
            System.out.println(randomAccessFile.readDouble());
        }
    }
}
